package com.springdoor.wx.api.controller;

import com.springdoor.wx.api.entity.ResultSkuDetail;
import com.springdoor.wx.core.controller.BaseController;
import com.springdoor.wx.core.domain.AjaxResult;
import com.springdoor.wx.core.page.TableDataInfo;
import com.springdoor.wx.api.entity.SprdGoodsShop;
import com.springdoor.wx.api.service.SprdGoodsShopService;
import com.springdoor.wx.utils.string.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("shop")
@RestController
public class SprdGoodsShopController extends BaseController {

    @Autowired
    private SprdGoodsShopService goodsShopService;



    @RequestMapping("list")
//    @Log(title = "商品信息->全部查询", businessType = BusinessType.OTHER)
    public AjaxResult list(@RequestBody SprdGoodsShop sprdGoodsShop) {
        if (sprdGoodsShop == null) sprdGoodsShop = new SprdGoodsShop();
        return success(goodsShopService.list(sprdGoodsShop));
    }

    @RequestMapping("listPage")
//    @Log(title = "商品信息->分页查询", businessType = BusinessType.OTHER)
    public TableDataInfo listPage(SprdGoodsShop sprdGoodsShop) {
        startPage();
        return getDataTable(goodsShopService.list(sprdGoodsShop));
    }

    @RequestMapping("fetchInfoBySkuId/{gshopId}")
    public AjaxResult fetchInfoBySkuId(@PathVariable String gshopId) {
        if (StringUtils.isEmpty(gshopId)) {
            return error("订单号不能为空");
        }
        ResultSkuDetail sku = goodsShopService.fetchInfoByGShopId(gshopId);
        if (sku == null) {
            return error("该商品不存在");
        }
        return success(sku);
    }

    @RequestMapping("fetchSpecInfoBySkuId/{skuId}")
    public AjaxResult fetchSpecInfoBySkuId(@PathVariable String skuId) {
        if (StringUtils.isEmpty(skuId)) {
            return error("订单号不能为空");
        }
        ResultSkuDetail sku = goodsShopService.fetchSpecInfoBySkuId(skuId);
        if (sku == null) {
            return error("该商品不存在");
        }
        return success(sku);
    }
}
